package my.kwantlen.assignment2;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.widget.TextView;
import android.view.View;
import android.view.View.OnClickListener;
import android.content.SharedPreferences;

public class settings extends Activity {
	private Button confirmButton;
	private Button cancelButton;
	String host; 
	String username;
	String password;
	int port;
	SharedPreferences mySharedPreferences;
	
	final int mode = Activity.MODE_PRIVATE;
	final String MYPREFS = "MySettings_001";

	SharedPreferences.Editor myEditor;
	
	public void onCreate(Bundle savedInstanceState) {
    	super.onCreate(savedInstanceState);
    	setContentView(R.layout.settings);
    	
	  	  
  	  this.confirmButton = (Button)this.findViewById(R.id.confirmSettings);
  	  this.confirmButton.setOnClickListener(new OnClickListener() {
  	    public void onClick(View v) {
  	    	SharedPreferences mySharedPreferences = 
  	    			getSharedPreferences(MYPREFS, mode);
  	    	SharedPreferences.Editor myEditor = mySharedPreferences.edit();
  	    	TextView loginSetting = (TextView) findViewById(R.id.loginSetting);
  	    	myEditor.putString("userName", loginSetting.getText().toString());
  	    	TextView serverSetting = (TextView) findViewById(R.id.serverSetting);
  	    	myEditor.putString("serverIp", serverSetting.getText().toString()); 
  	    	TextView passwordSetting = (TextView) findViewById(R.id.passwordSetting);
  	    	myEditor.putString("userPassword", passwordSetting.getText().toString()); 
  	    	TextView portSetting = (TextView) findViewById(R.id.portSetting);
  	    	port = Integer.parseInt(portSetting.getText().toString());
  	    	myEditor.putInt("port", port);
  	    	myEditor.commit();
  	    		Intent i = new Intent();
              i.setClassName("my.kwantlen.assignment2", "my.kwantlen.assignment2.Main");
              startActivity(i);
  	    }
  	  }); 
  	    	  
  	  this.cancelButton = (Button)this.findViewById(R.id.cancelSettings);
  	  this.cancelButton.setOnClickListener(new OnClickListener() {
  	    public void onClick(View v) {
  	    	Intent i = new Intent();
            i.setClassName("my.kwantlen.assignment2", "my.kwantlen.assignment2.Main");
            startActivity(i);
  	    }
  	  });  	  
  	  
  	  
  	  
	}
}
